{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "aacb2136",
   "metadata": {},
   "outputs": [],
   "source": [
    "from openai import OpenAI\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e90aedc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from modelscope import AutoModelForCausalLM, AutoTokenizer\n",
    "\n",
    "model_name = \"Qwen/Qwen3-8B\"\n",
    "model_name = \"Qwen/Qwen3-4B-Instruct-2507\"\n",
    "\n",
    "# load the tokenizer and the model\n",
    "tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
    "model = AutoModelForCausalLM.from_pretrained(\n",
    "    model_name,\n",
    "    torch_dtype=\"auto\",\n",
    "    device_map=\"auto\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4406b99e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# domain v1.0\n",
    "system_content_domain_v1 = \"\"\"\n",
    "### 角色定义 ###\n",
    "你是一位文本语义领域分类专家，擅长根据给定的领域类别对用户输入的短文本进行分类。\n",
    "### 核心技能 ###\n",
    "精准解析用户指令的语义意图\n",
    "准确匹配预定义领域类别\n",
    "### 任务说明 ###\n",
    "根据用户自然语言指令和以下类别列表，识别所属类别\n",
    "### 领域类别列表 ###\n",
    "1. 空调\n",
    "2. 系统设置\n",
    "3. 车辆控制\n",
    "4. 车辆信息查询\n",
    "5. 导航\n",
    "6. 电话\n",
    "7. 天气\n",
    "8. 音乐\n",
    "9. 视频\n",
    "10. 应用\n",
    "11. 日程\n",
    "12. 新闻\n",
    "13. 电台\n",
    "14. 火车\n",
    "15. 航班\n",
    "16. 股票\n",
    "### 格式示例 ###\n",
    "- 输入： \"打开车窗\"   → 输出： \"车辆控制\"\n",
    "- 输入： \"播放音乐\"   → 输出： \"音乐\"\n",
    "- 输入： \"明天气温多少\" → 输出： \"天气\"\n",
    "\n",
    "### 关键规则 ###\n",
    "1. 确保理解用户意图并分别正确映射类别\n",
    "2. 仅输出类别文本（无其他说明或思考过程）\n",
    "3. 未匹配类别时统一输出： \"其他\"\n",
    "4. 只能输出给定的以上类别，不能创造新的类别\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"查股票价格\" → 错误输出： \"金融类\" \n",
    "正确输出： \"股票\"\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "# domain v2.0 , 有二级分类，可作为intent\n",
    "system_content_domain_v2 = \"\"\"\n",
    "### 角色定义 ###\n",
    "你是一位文本语义领域分类专家，擅长根据给定的领域类别对用户输入的短文本进行分类。\n",
    "### 核心技能 ###\n",
    "精准解析用户指令的语义意图\n",
    "准确匹配预定义一级领域类别\n",
    "根据一级领域类别进一步准确匹配二级类别\n",
    "### 任务说明 ###\n",
    "根据用户自然语言指令和以下一级和二级类别列表，识别所属一级领域类别和二级领域类别，如果二级类别无法确认则只输出一级类别，一二级类别直接使用-连接\n",
    "### 领域类别列表 ###\n",
    "1. 空调\n",
    "-空调开关\n",
    "-温度调节\n",
    "-制冷制热\n",
    "-吹风模式\n",
    "-风速调节\n",
    "-出风口调节\n",
    "-其他模式\n",
    "2. 系统设置\n",
    "-屏幕\n",
    "-打开和关闭页面\n",
    "-声音\n",
    "-蓝牙和网络\n",
    "-壁纸\n",
    "3. 车辆控制\n",
    "-车窗\n",
    "-其他控制\n",
    "-座椅通风\n",
    "-车门控制\n",
    "-座椅加热\n",
    "-天窗\n",
    "-遮阳帘\n",
    "-座椅调节\n",
    "-座椅按摩\n",
    "4. 车辆信息查询\n",
    "5. 地图\n",
    "-导航\n",
    "-搜索\n",
    "-控制指令\n",
    "6. 电话\n",
    "-呼叫\n",
    "-控制指令\n",
    "7. 天气\n",
    "-查询\n",
    "8. 音乐\n",
    "-播放歌曲\n",
    "-搜索歌曲\n",
    "-控制指令\n",
    "9. 视频\n",
    "-播放视频\n",
    "-搜索视频\n",
    "-控制指令\n",
    "10. 应用\n",
    "11. 日程\n",
    "12. 新闻\n",
    "13. 电台\n",
    "14. 火车\n",
    "15. 航班\n",
    "16. 股票\n",
    "17. 闲聊\n",
    "### 格式示例 ###\n",
    "- 输入： \"打开车窗\"   → 输出： \"车辆控制-车窗\"\n",
    "- 输入： \"明天气温多少\" → 输出： \"天气-查询\"\n",
    "- 输入： \"你是谁\" → 输出： \"闲聊\"\n",
    "\n",
    "### 关键规则 ###\n",
    "1. 确保理解用户意图并分别正确映射一二级类别\n",
    "2. 仅输出类别文本（无其他说明或思考过程）\n",
    "3. 请注意辨别闲聊的意图，如何语义属于聊天内容，则输出: \"闲聊\"\n",
    "4. 只能输出给定的以上类别，不能创造新的类别\n",
    "5. 未匹配类别时统一输出： \"其他\"\n",
    "6. 若输入内容没有意义或涉及敏感，则输出： \"其他\"\n",
    "7. 若没有明显的音乐搜索和视频搜索的意图，请输出\"其他\"或\"闲聊\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"打开空调\"\n",
    "错误输出： \"应用\"\n",
    "正确输出： \"空调-空调开关\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"周杰伦\"\n",
    "错误输出： \"音乐-搜索歌曲\"\n",
    "正确输出： \"闲聊\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"听周杰伦\"\n",
    "错误输出： \"其他\"\n",
    "正确输出： \"音乐-搜索歌曲\"\n",
    "\"\"\"\n",
    "# 7. 对于音乐和视频领域，需要匹配到关键词才能输出，如\"听\",\"看\",\"放\",\"播\"等等\n",
    "# 8. 若没有明显的音乐搜索和视频搜索的意图，请输出\"其他\"或\"闲聊\"\n",
    "#8. 若没有明显的音乐搜索和视频搜索的意图，请输出\"其他\"或\"闲聊\"\n",
    "\n",
    "\n",
    "# domain v2.0 , 有二级分类，可作为intent\n",
    "system_content_domain_v3 = \"\"\"\n",
    "### 角色定义 ###\n",
    "你是一位文本语义领域分类专家，擅长根据给定的领域类别对用户输入的短文本进行分类。\n",
    "### 核心技能 ###\n",
    "精准解析用户指令的语义意图\n",
    "准确匹配预定义一级领域类别\n",
    "根据一级领域类别进一步准确匹配二级类别\n",
    "### 任务说明 ###\n",
    "根据用户自然语言指令和以下一级和二级类别列表，识别所属一级领域类别和二级领域类别，如果二级类别无法确认则只输出一级类别，一二级类别直接使用-连接\n",
    "### 领域类别列表 ###\n",
    "1. 空调\n",
    "-空调开关\n",
    "-温度调节\n",
    "-制冷制热\n",
    "-吹风模式\n",
    "-风速调节\n",
    "-出风口调节\n",
    "-其他模式\n",
    "2. 系统设置\n",
    "-屏幕\n",
    "-打开和关闭页面\n",
    "-声音\n",
    "-蓝牙和网络\n",
    "-壁纸\n",
    "3. 车辆控制\n",
    "-车窗\n",
    "-其他控制\n",
    "-座椅通风\n",
    "-车门控制\n",
    "-座椅加热\n",
    "-天窗\n",
    "-遮阳帘\n",
    "-座椅调节\n",
    "-座椅按摩\n",
    "4. 车辆信息查询\n",
    "5. 地图\n",
    "-导航\n",
    "-搜索\n",
    "-控制指令\n",
    "6. 电话\n",
    "-呼叫\n",
    "-控制指令\n",
    "7. 天气\n",
    "-查询\n",
    "8. 音乐\n",
    "9. 视频\n",
    "10. 应用\n",
    "11. 日程\n",
    "12. 新闻\n",
    "13. 电台\n",
    "14. 火车\n",
    "15. 航班\n",
    "16. 股票\n",
    "17. 闲聊\n",
    "### 格式示例 ###\n",
    "- 输入： \"打开车窗\"   → 输出： \"车辆控制-车窗\"\n",
    "- 输入： \"明天气温多少\" → 输出： \"天气-查询\"\n",
    "- 输入： \"你是谁\" → 输出： \"闲聊\"\n",
    "\n",
    "### 关键规则 ###\n",
    "1. 确保理解用户意图并分别正确映射一二级类别\n",
    "2. 仅输出类别文本（无其他说明或思考过程）\n",
    "3. 请注意辨别闲聊的意图，如何语义属于聊天内容，则输出: \"闲聊\"\n",
    "4. 只能输出给定的以上类别，不能创造新的类别\n",
    "5. 未匹配类别时统一输出： \"其他\"\n",
    "6. 若输入内容没有意义或涉及敏感，则输出： \"其他\"\n",
    "7. 若没有明显的音乐搜索和视频搜索的意图，请输出\"其他\"或\"闲聊\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"打开空调\"\n",
    "错误输出： \"应用\"\n",
    "正确输出： \"空调-空调开关\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"周杰伦\"\n",
    "错误输出： \"音乐\"\n",
    "正确输出： \"闲聊\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"听周杰伦\"\n",
    "错误输出： \"其他\"\n",
    "正确输出： \"音乐\"\n",
    "\"\"\"\n",
    "\n",
    "system_content_semantic_v1 = \"\"\"\n",
    "### 角色定义 ###\n",
    "你是一位文本领域语义理解专家，擅长根据用户输入的短文本对给定的语义槽位进行填充。\n",
    "\n",
    "### 核心技能 ###\n",
    "精准解析用户指令的语义意图\n",
    "准确匹配槽位，提取准确的槽值\n",
    "\n",
    "### 任务说明 ###\n",
    "理解文本所属领域和意图\n",
    "理解每个槽位意义和可选项\n",
    "从文本提取信息并填充槽值\n",
    "\n",
    "### 格式示例 ###\n",
    "-输入:\n",
    "text:把空调风量调大三挡\n",
    "domain:空调\n",
    "intent:风速调节\n",
    "mode:风速\n",
    "degree:最高|中等|最低|高|低\n",
    "object:空调\n",
    "operate:调成|调低|调高\n",
    "position:\n",
    "value:\n",
    "\n",
    "-输出：\n",
    "text:把空调风量调大三挡\n",
    "domain:空调\n",
    "intent:风速调节\n",
    "mode:风速\n",
    "object:空调\n",
    "operate:调高\n",
    "value:3\n",
    "\n",
    "### 格式示例 ###\n",
    "-输入:\n",
    "text:明天南京有雨吗\n",
    "domain:天气\n",
    "intent:查询\n",
    "type:天气|晴|多云|阴|雨|雾霾|雪|气温\n",
    "location:\n",
    "time:\n",
    "\n",
    "-输出:\n",
    "text:明天南京有雨吗\n",
    "domain:天气\n",
    "intent:查询\n",
    "object:雨\n",
    "city:南京\n",
    "time:明天\n",
    "\n",
    "### 格式示例 ###\n",
    "-输入:\n",
    "text:去南京南站顺便路过玄武湖\n",
    "domain:地图\n",
    "intent:导航\n",
    "origin:\n",
    "destination:\n",
    "strategy:默认|速度优先|费用优先|躲避拥堵|高速优先|不走高速|大路优先\n",
    "waypoints:\n",
    "\n",
    "-输出:\n",
    "text:去南京南站顺便路过玄武湖\n",
    "domain:地图\n",
    "intent:导航\n",
    "destination:南京南站\n",
    "strategy:默认\n",
    "waypoints:玄武湖\n",
    "\n",
    "### 格式示例 ###\n",
    "-输入:\n",
    "text:从南京南站去镇江南站最快的路\n",
    "domain:地图\n",
    "intent:导航\n",
    "origin:\n",
    "destination:\n",
    "strategy:默认|速度优先|费用优先|躲避拥堵|高速优先|不走高速|大路优先\n",
    "waypoints:\n",
    "\n",
    "-输出:\n",
    "text:从南京南站去镇江南站最快的路\n",
    "domain:地图\n",
    "intent:导航\n",
    "origin:南京南站\n",
    "destination:镇江南站\n",
    "strategy:速度优先\n",
    "\n",
    "### 关键规则 ###\n",
    "1. 只能在给定的槽位范围内填充,不能增加新的槽位\n",
    "2. 若槽位给出可选项,则只能在选项范围内选择,不能增加新的选项\n",
    "3. 若槽位没有给出可选项,则需要根据文本进行提取\n",
    "4. 提取内容要结合槽位的意义\n",
    "5. 若无法提取有效的槽值,则不输出该槽位\n",
    "\"\"\"\n",
    "\n",
    "system_content_semantic_v2 = \"\"\"\n",
    "### 角色定义 ###\n",
    "你是一个智能座舱语音助手的语义理解模块。你的任务是对给定的槽位进行槽值填充。\n",
    "\n",
    "### 核心技能 ###\n",
    "精准解析用户指令的语义意图\n",
    "准确匹配槽位，提取准确的槽值\n",
    "\n",
    "### 工作流程 ###\n",
    "首先基于text,domain,intent理解文本的所属领域和意图\n",
    "然后基于slot槽位含义和可选项，理解每个槽位意义和可选项\n",
    "从text中提取信息并填充槽值\n",
    "\n",
    "### 格式解读 ###\n",
    "输入为json格式,包含text,domain,intent,slot字段\n",
    "其中text,domain,intent为已知项，你需要理解和记忆\n",
    "slot为需要填充的槽位，不同的domain和intent有不同的slot\n",
    "slot中已经存在槽位，你需要理解槽位名称的含义，不需要额外增加新的槽位\n",
    "slot中的槽值有多种格式，有字符串列表、空字符串及已知的字符串;若为列表，你必须从中选择一项作为槽值；若为空字符串，你需要从文本中抽取槽值进行填充。\n",
    "\n",
    "\n",
    "### 格式示例 ###\n",
    "-输入:\n",
    "{\n",
    "    \"text\":\"打开前排空调\",\n",
    "    \"domain\":\"空调\",\n",
    "    \"intent\":\"空调开关\",\n",
    "    \"slot\":{\n",
    "        \"object\": [\"空调\", \"出风口\"],\n",
    "        \"operate\": [\"打开\", \"关闭\", \"锁定\", \"解锁\"],\n",
    "        \"position\": \"\"\n",
    "    }\n",
    "}\n",
    "-输出：\n",
    "{\n",
    "    \"text\":\"打开前排空调\",\n",
    "    \"domain\":\"空调\",\n",
    "    \"intent\":\"空调开关\",\n",
    "    \"slot\":{\n",
    "        \"object\": \"空调\",\n",
    "        \"operate\": \"打开\", \n",
    "        \"position\": \"前排\"\n",
    "    }\n",
    "}\n",
    "####\n",
    "-输入：\n",
    "{\n",
    "    \"text\":\"把空调风量调大三挡\",\n",
    "    \"domain\":\"空调\",\n",
    "    \"intent\":\"温度调节\",\n",
    "    \"slot\":{    \n",
    "        \"mode\": [\"温度\"],\n",
    "        \"degree\": [\"最高\", \"中等\", \"最低\", \"高\", \"低\"],\n",
    "        \"object\": [\"空调\"],\n",
    "        \"operate\": [\"调成\", \"调高\", \"调低\"],\n",
    "        \"position\": \"\",\n",
    "        \"value\": \"\"\n",
    "    }\n",
    "}\n",
    "\n",
    "-输出：\n",
    "{\n",
    "    \"text\":\"把空调风量调大三挡\",\n",
    "    \"domain\":\"空调\",\n",
    "    \"intent\":\"温度调节\",\n",
    "    \"slot\":{    \n",
    "        \"mode\": [\"温度\"],\n",
    "        \"object\": \"空调\",\n",
    "        \"operate\": \"调高\",\n",
    "        \"value\": \"3\"\n",
    "    }\n",
    "}\n",
    "####\n",
    "-输入:\n",
    "{\n",
    "    \"text\":\"明天南京有雨吗\",\n",
    "    \"domain\":\"天气\",\n",
    "    \"intent\":\"查询\",\n",
    "    \"slot\":{    \n",
    "        \"object\": [\"天气\", \"晴\", \"多云\", \"阴\", \"雨\", \"雾霾\", \"雪\", \"气温\"],\n",
    "        \"operate\": \"查询\",\n",
    "        \"city\": \"\",\n",
    "        \"time\": \"\"\n",
    "    }\n",
    "}\n",
    "\n",
    "-输出:\n",
    "{\n",
    "    \"text\":\"明天南京有雨吗\",\n",
    "    \"domain\":\"天气\",\n",
    "    \"intent\":\"查询\",\n",
    "    \"slot\":{    \n",
    "        \"object\": \"雨\",\n",
    "        \"operate\": \"查询\",\n",
    "        \"city\": \"南京\",\n",
    "        \"time\": \"明天\"\n",
    "    }\n",
    "}\n",
    "####\n",
    "-输入:\n",
    "{\n",
    "    \"text\":\"去南京南站顺便路过玄武湖\",\n",
    "    \"domain\":\"地图\",\n",
    "    \"intent\":\"导航\",\n",
    "    \"slot\":{    \n",
    "        \"origin\": \"\",\n",
    "        \"destination\": \"\",\n",
    "        \"strategy\": [\"默认\", \"速度优先\", \"费用优先\", \"躲避拥堵\", \"高速优先\", \"不走高速\", \"大路优先\"],\n",
    "        \"waypoints\": \"\"\n",
    "    }\n",
    "}\n",
    "-输出:\n",
    "{\n",
    "    \"text\":\"去南京南站顺便路过玄武湖\",\n",
    "    \"domain\":\"地图\",\n",
    "    \"intent\":\"导航\",\n",
    "    \"slot\":{\n",
    "        \"destination\": \"南京南站\",\n",
    "        \"strategy\": \"默认\",\n",
    "        \"waypoints\": \"玄武湖\"\n",
    "    }\n",
    "}\n",
    "####\n",
    "-输入:\n",
    "{\n",
    "    \"text\":\"从南京南站去镇江南站最快的路\",\n",
    "    \"domain\":\"地图\",\n",
    "    \"intent\":\"导航\",\n",
    "    \"slot\":{\n",
    "        \"origin\": \"\",\n",
    "        \"destination\": \"\",\n",
    "        \"strategy\": [\"默认\", \"速度优先\", \"费用优先\", \"躲避拥堵\", \"高速优先\", \"不走高速\", \"大路优先\"],\n",
    "        \"waypoints\": \"\"\n",
    "    }\n",
    "}\n",
    "-输出:\n",
    "{\n",
    "    \"text\":\"从南京南站去镇江南站最快的路\",\n",
    "    \"domain\":\"地图\",\n",
    "    \"intent\":\"导航\",\n",
    "    \"slot\":{\n",
    "        \"origin\": \"南京南站\",\n",
    "        \"destination\": \"镇江南站\",\n",
    "        \"strategy\": \"速度优先\",\n",
    "        \"waypoints\": \"玄武湖\"\n",
    "    }\n",
    "}\n",
    "\n",
    "### 关键规则 ###\n",
    "1. 只能在给定的槽位范围内填充,不能增加新的槽位\n",
    "2. 若槽位给出可选项,则只能在选项范围内选择,不能增加新的选项\n",
    "3. 若槽位没有给出可选项,则需要根据文本进行提取\n",
    "4. 提取内容要结合槽位的意义\n",
    "5. 若无法提取有效的槽值,则不输出该槽位\n",
    "6. 保持原json格式输出，不能增加新的字段\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2d4b0b69",
   "metadata": {},
   "outputs": [],
   "source": [
    "system_content_domain = \"\"\"\n",
    "### 角色定义 ###\n",
    "你是一位文本语义领域分类专家，擅长根据给定的领域类别对用户输入的短文本进行分类。\n",
    "### 核心技能 ###\n",
    "精准解析用户指令的语义意图\n",
    "准确匹配预定义一级领域类别\n",
    "根据一级领域类别进一步准确匹配二级类别\n",
    "### 任务说明 ###\n",
    "根据用户自然语言指令和以下一级和二级类别列表，识别所属一级领域类别和二级领域类别，如果二级类别无法确认则只输出一级类别，一二级类别直接使用-连接\n",
    "### 领域类别列表 ###\n",
    "1. 空调\n",
    "-空调开关\n",
    "-温度调节\n",
    "-制冷制热\n",
    "-吹风模式\n",
    "-风速调节\n",
    "-出风口调节\n",
    "-其他模式\n",
    "2. 系统设置\n",
    "-屏幕\n",
    "-打开和关闭页面\n",
    "-声音\n",
    "-蓝牙和网络\n",
    "-壁纸\n",
    "3. 车辆控制\n",
    "-车窗\n",
    "-其他控制\n",
    "-座椅通风\n",
    "-车门控制\n",
    "-座椅加热\n",
    "-天窗\n",
    "-遮阳帘\n",
    "-座椅调节\n",
    "-座椅按摩\n",
    "4. 车辆信息查询\n",
    "5. 导航\n",
    "-导航\n",
    "-搜索\n",
    "-控制指令\n",
    "6. 电话\n",
    "-呼叫\n",
    "-指令\n",
    "7. 天气\n",
    "-查询\n",
    "8. 音乐\n",
    "-播放歌曲\n",
    "-歌曲控制\n",
    "9. 视频\n",
    "-视频播放\n",
    "-视频控制\n",
    "10. 应用\n",
    "11. 日程\n",
    "12. 新闻\n",
    "13. 电台\n",
    "14. 火车\n",
    "15. 航班\n",
    "16. 股票\n",
    "17. 闲聊\n",
    "### 格式示例 ###\n",
    "- 输入： \"打开车窗\"   → 输出： \"车辆控制-车窗\"\n",
    "- 输入： \"明天气温多少\" → 输出： \"天气-查询\"\n",
    "- 输入： \"你是谁\" → 输出： \"闲聊\"\n",
    "\n",
    "### 关键规则 ###\n",
    "1. 确保理解用户意图并分别正确映射一二级类别\n",
    "2. 仅输出类别文本（无其他说明或思考过程）\n",
    "3. 请注意辨别闲聊的意图，如何语义属于聊天内容，则输出: \"闲聊\"\n",
    "4. 只能输出给定的以上类别，不能创造新的类别\n",
    "5. 未匹配类别时统一输出： \"其他\"\n",
    "6. 若输入内容没有意义或涉及敏感，则输出： \"其他\"\n",
    "7. 若没有明显的音乐搜索和视频搜索的意图，请输出\"其他\"或\"闲聊\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"打开空调\"\n",
    "错误输出： \"应用\"\n",
    "正确输出： \"空调-空调开关\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"周杰伦\"\n",
    "错误输出： \"音乐\"\n",
    "正确输出： \"闲聊\"\n",
    "\n",
    "### 错误示例 ###\n",
    "输入： \"听周杰伦\"\n",
    "错误输出： \"其他\"\n",
    "正确输出： \"音乐\"\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "774e54ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "地图-搜索\n"
     ]
    }
   ],
   "source": [
    "# 快速测试服务\n",
    "openai_api_key = \"EMPTY\"\n",
    "openai_api_base = \"http://localhost:10085/v1\"\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=openai_api_key,\n",
    "    base_url=openai_api_base,\n",
    ")\n",
    "chat_response = client.chat.completions.create(\n",
    "    model=\"lora_domain\",\n",
    "    # model=\"lora\",\n",
    "    messages=[\n",
    "        {\"role\": \"system\", \"content\": system_content_domain_v3},\n",
    "        {\"role\": \"user\", \"content\": \"芜湖有什么好吃的\"},\n",
    "    ],\n",
    "    temperature=0.3,\n",
    "    max_tokens=16,\n",
    "    extra_body={\"chat_template_kwargs\": {\"enable_thinking\": False}}\n",
    ")\n",
    "# print(\"Chat response:\", chat_response)\n",
    "print(f\"{chat_response.choices[0].message.content}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bbde08df",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/renchong/miniconda3/envs/vllm/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO 09-02 19:58:45 [__init__.py:244] Automatically detected platform cuda.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-09-02 19:58:48,139\tINFO util.py:154 -- Missing packages: ['ipywidgets']. Run `pip install -U ipywidgets`, then restart the notebook server for rich notebook output.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING 09-02 19:58:57 [arg_utils.py:1642] --task classify is not supported by the V1 Engine. Falling back to V0. \n",
      "WARNING 09-02 19:58:57 [arg_utils.py:1490] The model has a long context length (262144). This may causeOOM during the initial memory profiling phase, or result in low performance due to small KV cache size. Consider setting --max-model-len to a smaller value.\n",
      "WARNING 09-02 19:58:57 [cuda.py:91] To see benefits of async output processing, enable CUDA graph. Since, enforce-eager is enabled, async output processor cannot be used\n",
      "INFO 09-02 19:58:57 [llm_engine.py:230] Initializing a V0 LLM engine (v0.9.1) with config: model='/home/renchong/.cache/modelscope/hub/Qwen/Qwen3-4B-Instruct-2507', speculative_config=None, tokenizer='/home/renchong/.cache/modelscope/hub/Qwen/Qwen3-4B-Instruct-2507', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, override_neuron_config={}, tokenizer_revision=None, trust_remote_code=False, dtype=torch.bfloat16, max_seq_len=262144, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=None, enforce_eager=True, kv_cache_dtype=auto,  device_config=cuda, decoding_config=DecodingConfig(backend='auto', disable_fallback=False, disable_any_whitespace=False, disable_additional_properties=False, reasoning_backend=''), observability_config=ObservabilityConfig(show_hidden_metrics_for_version=None, otlp_traces_endpoint=None, collect_detailed_traces=None), seed=0, served_model_name=/home/renchong/.cache/modelscope/hub/Qwen/Qwen3-4B-Instruct-2507, num_scheduler_steps=1, multi_step_stream_outputs=True, enable_prefix_caching=None, chunked_prefill_enabled=False, use_async_output_proc=False, pooler_config=PoolerConfig(pooling_type=None, normalize=None, softmax=None, step_tag_id=None, returned_token_ids=None), compilation_config={\"level\":0,\"debug_dump_path\":\"\",\"cache_dir\":\"\",\"backend\":\"\",\"custom_ops\":[],\"splitting_ops\":[],\"use_inductor\":true,\"compile_sizes\":[],\"inductor_compile_config\":{\"enable_auto_functionalized_v2\":false},\"inductor_passes\":{},\"use_cudagraph\":true,\"cudagraph_num_of_warmups\":0,\"cudagraph_capture_sizes\":[],\"cudagraph_copy_inputs\":false,\"full_cuda_graph\":false,\"max_capture_size\":0,\"local_cache_dir\":null}, use_cached_outputs=False, \n",
      "WARNING 09-02 19:58:59 [interface.py:376] Using 'pin_memory=False' as WSL is detected. This may slow down the performance.\n",
      "INFO 09-02 19:58:59 [cuda.py:327] Using Flash Attention backend.\n",
      "INFO 09-02 19:59:02 [parallel_state.py:1065] rank 0 in world size 1 is assigned as DP rank 0, PP rank 0, TP rank 0, EP rank 0\n",
      "INFO 09-02 19:59:02 [model_runner.py:1171] Starting to load model /home/renchong/.cache/modelscope/hub/Qwen/Qwen3-4B-Instruct-2507...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Loading safetensors checkpoint shards:   0% Completed | 0/3 [00:00<?, ?it/s]\n",
      "Loading safetensors checkpoint shards:  33% Completed | 1/3 [00:00<00:00,  7.84it/s]\n",
      "Loading safetensors checkpoint shards:  67% Completed | 2/3 [00:05<00:03,  3.26s/it]\n",
      "Loading safetensors checkpoint shards: 100% Completed | 3/3 [00:11<00:00,  4.45s/it]\n",
      "Loading safetensors checkpoint shards: 100% Completed | 3/3 [00:11<00:00,  3.82s/it]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO 09-02 19:59:14 [default_loader.py:272] Loading weights took 11.54 seconds\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "Following weights were not initialized from checkpoint: {'score.weight'}",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mValueError\u001b[39m                                Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 16\u001b[39m\n\u001b[32m      7\u001b[39m prompts = [\n\u001b[32m      8\u001b[39m     \u001b[33m\"\u001b[39m\u001b[33mHello, my name is\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m      9\u001b[39m     \u001b[33m\"\u001b[39m\u001b[33mThe president of the United States is\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m     10\u001b[39m     \u001b[33m\"\u001b[39m\u001b[33mThe capital of France is\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m     11\u001b[39m     \u001b[33m\"\u001b[39m\u001b[33mThe future of AI is\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m     12\u001b[39m ]\n\u001b[32m     14\u001b[39m \u001b[38;5;66;03m# Create an LLM.\u001b[39;00m\n\u001b[32m     15\u001b[39m \u001b[38;5;66;03m# You should pass task=\"classify\" for classification models\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m16\u001b[39m model = \u001b[43mLLM\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m     17\u001b[39m \u001b[43m    \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m/home/renchong/.cache/modelscope/hub/Qwen/Qwen3-4B-Instruct-2507\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m     18\u001b[39m \u001b[43m    \u001b[49m\u001b[43mtask\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mclassify\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m     19\u001b[39m \u001b[43m    \u001b[49m\u001b[43menforce_eager\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m     20\u001b[39m \u001b[43m)\u001b[49m\n\u001b[32m     22\u001b[39m \u001b[38;5;66;03m# Generate logits. The output is a list of ClassificationRequestOutputs.\u001b[39;00m\n\u001b[32m     23\u001b[39m outputs = model.classify(prompts)\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/entrypoints/llm.py:243\u001b[39m, in \u001b[36mLLM.__init__\u001b[39m\u001b[34m(self, model, task, tokenizer, tokenizer_mode, skip_tokenizer_init, trust_remote_code, allowed_local_media_path, tensor_parallel_size, dtype, quantization, revision, tokenizer_revision, seed, gpu_memory_utilization, swap_space, cpu_offload_gb, enforce_eager, max_seq_len_to_capture, disable_custom_all_reduce, disable_async_output_proc, hf_token, hf_overrides, mm_processor_kwargs, override_pooler_config, compilation_config, **kwargs)\u001b[39m\n\u001b[32m    213\u001b[39m engine_args = EngineArgs(\n\u001b[32m    214\u001b[39m     model=model,\n\u001b[32m    215\u001b[39m     task=task,\n\u001b[32m   (...)\u001b[39m\u001b[32m    239\u001b[39m     **kwargs,\n\u001b[32m    240\u001b[39m )\n\u001b[32m    242\u001b[39m \u001b[38;5;66;03m# Create the Engine (autoselects V0 vs V1)\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m243\u001b[39m \u001b[38;5;28mself\u001b[39m.llm_engine = \u001b[43mLLMEngine\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfrom_engine_args\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m    244\u001b[39m \u001b[43m    \u001b[49m\u001b[43mengine_args\u001b[49m\u001b[43m=\u001b[49m\u001b[43mengine_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43musage_context\u001b[49m\u001b[43m=\u001b[49m\u001b[43mUsageContext\u001b[49m\u001b[43m.\u001b[49m\u001b[43mLLM_CLASS\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m    245\u001b[39m \u001b[38;5;28mself\u001b[39m.engine_class = \u001b[38;5;28mtype\u001b[39m(\u001b[38;5;28mself\u001b[39m.llm_engine)\n\u001b[32m    247\u001b[39m \u001b[38;5;28mself\u001b[39m.request_counter = Counter()\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/engine/llm_engine.py:501\u001b[39m, in \u001b[36mLLMEngine.from_engine_args\u001b[39m\u001b[34m(cls, engine_args, usage_context, stat_loggers)\u001b[39m\n\u001b[32m    498\u001b[39m     \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mvllm\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mv1\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mengine\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mllm_engine\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m LLMEngine \u001b[38;5;28;01mas\u001b[39;00m V1LLMEngine\n\u001b[32m    499\u001b[39m     engine_cls = V1LLMEngine\n\u001b[32m--> \u001b[39m\u001b[32m501\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mengine_cls\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfrom_vllm_config\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m    502\u001b[39m \u001b[43m    \u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m=\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    503\u001b[39m \u001b[43m    \u001b[49m\u001b[43musage_context\u001b[49m\u001b[43m=\u001b[49m\u001b[43musage_context\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    504\u001b[39m \u001b[43m    \u001b[49m\u001b[43mstat_loggers\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstat_loggers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    505\u001b[39m \u001b[43m    \u001b[49m\u001b[43mdisable_log_stats\u001b[49m\u001b[43m=\u001b[49m\u001b[43mengine_args\u001b[49m\u001b[43m.\u001b[49m\u001b[43mdisable_log_stats\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    506\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/engine/llm_engine.py:477\u001b[39m, in \u001b[36mLLMEngine.from_vllm_config\u001b[39m\u001b[34m(cls, vllm_config, usage_context, stat_loggers, disable_log_stats)\u001b[39m\n\u001b[32m    469\u001b[39m \u001b[38;5;129m@classmethod\u001b[39m\n\u001b[32m    470\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mfrom_vllm_config\u001b[39m(\n\u001b[32m    471\u001b[39m     \u001b[38;5;28mcls\u001b[39m,\n\u001b[32m   (...)\u001b[39m\u001b[32m    475\u001b[39m     disable_log_stats: \u001b[38;5;28mbool\u001b[39m = \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[32m    476\u001b[39m ) -> \u001b[33m\"\u001b[39m\u001b[33mLLMEngine\u001b[39m\u001b[33m\"\u001b[39m:\n\u001b[32m--> \u001b[39m\u001b[32m477\u001b[39m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[32m    478\u001b[39m \u001b[43m        \u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m=\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    479\u001b[39m \u001b[43m        \u001b[49m\u001b[43mexecutor_class\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_get_executor_cls\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    480\u001b[39m \u001b[43m        \u001b[49m\u001b[43mlog_stats\u001b[49m\u001b[43m=\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mdisable_log_stats\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    481\u001b[39m \u001b[43m        \u001b[49m\u001b[43musage_context\u001b[49m\u001b[43m=\u001b[49m\u001b[43musage_context\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    482\u001b[39m \u001b[43m        \u001b[49m\u001b[43mstat_loggers\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstat_loggers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m    483\u001b[39m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/engine/llm_engine.py:265\u001b[39m, in \u001b[36mLLMEngine.__init__\u001b[39m\u001b[34m(self, vllm_config, executor_class, log_stats, usage_context, stat_loggers, mm_registry, use_cached_outputs)\u001b[39m\n\u001b[32m    258\u001b[39m \u001b[38;5;28mself\u001b[39m.generation_config_fields = (\n\u001b[32m    259\u001b[39m     \u001b[38;5;28mself\u001b[39m.model_config.try_get_generation_config())\n\u001b[32m    261\u001b[39m \u001b[38;5;28mself\u001b[39m.input_preprocessor = InputPreprocessor(\u001b[38;5;28mself\u001b[39m.model_config,\n\u001b[32m    262\u001b[39m                                             \u001b[38;5;28mself\u001b[39m.tokenizer,\n\u001b[32m    263\u001b[39m                                             mm_registry)\n\u001b[32m--> \u001b[39m\u001b[32m265\u001b[39m \u001b[38;5;28mself\u001b[39m.model_executor = \u001b[43mexecutor_class\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m=\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m    267\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.model_config.runner_type != \u001b[33m\"\u001b[39m\u001b[33mpooling\u001b[39m\u001b[33m\"\u001b[39m:\n\u001b[32m    268\u001b[39m     \u001b[38;5;28mself\u001b[39m._initialize_kv_caches()\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/executor/executor_base.py:53\u001b[39m, in \u001b[36mExecutorBase.__init__\u001b[39m\u001b[34m(self, vllm_config)\u001b[39m\n\u001b[32m     51\u001b[39m \u001b[38;5;28mself\u001b[39m.prompt_adapter_config = vllm_config.prompt_adapter_config\n\u001b[32m     52\u001b[39m \u001b[38;5;28mself\u001b[39m.observability_config = vllm_config.observability_config\n\u001b[32m---> \u001b[39m\u001b[32m53\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_init_executor\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m     54\u001b[39m \u001b[38;5;28mself\u001b[39m.is_sleeping = \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[32m     55\u001b[39m \u001b[38;5;28mself\u001b[39m.sleeping_tags: \u001b[38;5;28mset\u001b[39m[\u001b[38;5;28mstr\u001b[39m] = \u001b[38;5;28mset\u001b[39m()\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/executor/uniproc_executor.py:48\u001b[39m, in \u001b[36mUniProcExecutor._init_executor\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m     46\u001b[39m \u001b[38;5;28mself\u001b[39m.collective_rpc(\u001b[33m\"\u001b[39m\u001b[33minit_worker\u001b[39m\u001b[33m\"\u001b[39m, args=([kwargs], ))\n\u001b[32m     47\u001b[39m \u001b[38;5;28mself\u001b[39m.collective_rpc(\u001b[33m\"\u001b[39m\u001b[33minit_device\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m---> \u001b[39m\u001b[32m48\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcollective_rpc\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mload_model\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/executor/uniproc_executor.py:57\u001b[39m, in \u001b[36mUniProcExecutor.collective_rpc\u001b[39m\u001b[34m(self, method, timeout, args, kwargs)\u001b[39m\n\u001b[32m     55\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m kwargs \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m     56\u001b[39m     kwargs = {}\n\u001b[32m---> \u001b[39m\u001b[32m57\u001b[39m answer = \u001b[43mrun_method\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mdriver_worker\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m     58\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m [answer]\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/utils.py:2671\u001b[39m, in \u001b[36mrun_method\u001b[39m\u001b[34m(obj, method, args, kwargs)\u001b[39m\n\u001b[32m   2669\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m   2670\u001b[39m     func = partial(method, obj)  \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m2671\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/worker/worker.py:210\u001b[39m, in \u001b[36mWorker.load_model\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m    208\u001b[39m     context = nullcontext()\n\u001b[32m    209\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m context:\n\u001b[32m--> \u001b[39m\u001b[32m210\u001b[39m     \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mmodel_runner\u001b[49m\u001b[43m.\u001b[49m\u001b[43mload_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/worker/model_runner.py:1174\u001b[39m, in \u001b[36mGPUModelRunnerBase.load_model\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m   1172\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m DeviceMemoryProfiler(\u001b[38;5;28mself\u001b[39m.device) \u001b[38;5;28;01mas\u001b[39;00m m:\n\u001b[32m   1173\u001b[39m     time_before_load = time.perf_counter()\n\u001b[32m-> \u001b[39m\u001b[32m1174\u001b[39m     \u001b[38;5;28mself\u001b[39m.model = \u001b[43mget_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m   1175\u001b[39m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.lora_config:\n\u001b[32m   1176\u001b[39m         \u001b[38;5;28;01massert\u001b[39;00m supports_lora(\n\u001b[32m   1177\u001b[39m             \u001b[38;5;28mself\u001b[39m.model\n\u001b[32m   1178\u001b[39m         ), \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m.model.\u001b[34m__class__\u001b[39m.\u001b[34m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m does not support LoRA yet.\u001b[39m\u001b[33m\"\u001b[39m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/model_executor/model_loader/__init__.py:59\u001b[39m, in \u001b[36mget_model\u001b[39m\u001b[34m(vllm_config, model_config)\u001b[39m\n\u001b[32m     57\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m model_config \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m     58\u001b[39m     model_config = vllm_config.model_config\n\u001b[32m---> \u001b[39m\u001b[32m59\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mloader\u001b[49m\u001b[43m.\u001b[49m\u001b[43mload_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m=\u001b[49m\u001b[43mvllm_config\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m     60\u001b[39m \u001b[43m                         \u001b[49m\u001b[43mmodel_config\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmodel_config\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/model_executor/model_loader/base_loader.py:41\u001b[39m, in \u001b[36mBaseModelLoader.load_model\u001b[39m\u001b[34m(self, vllm_config, model_config)\u001b[39m\n\u001b[32m     38\u001b[39m         model = initialize_model(vllm_config=vllm_config,\n\u001b[32m     39\u001b[39m                                  model_config=model_config)\n\u001b[32m     40\u001b[39m     \u001b[38;5;66;03m# Quantization does not happen in `load_weights` but after it\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m41\u001b[39m     \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mload_weights\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel_config\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m     42\u001b[39m     process_weights_after_loading(model, model_config, target_device)\n\u001b[32m     43\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m model.eval()\n",
      "\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/model_executor/model_loader/default_loader.py:281\u001b[39m, in \u001b[36mDefaultModelLoader.load_weights\u001b[39m\u001b[34m(self, model, model_config)\u001b[39m\n\u001b[32m    279\u001b[39m weights_not_loaded = weights_to_load - loaded_weights\n\u001b[32m    280\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m weights_not_loaded:\n\u001b[32m--> \u001b[39m\u001b[32m281\u001b[39m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[33m\"\u001b[39m\u001b[33mFollowing weights were not initialized from \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m    282\u001b[39m                      \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mcheckpoint: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mweights_not_loaded\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m)\n",
      "\u001b[31mValueError\u001b[39m: Following weights were not initialized from checkpoint: {'score.weight'}"
     ]
    }
   ],
   "source": [
    "# SPDX-License-Identifier: Apache-2.0\n",
    "\n",
    "from vllm import LLM\n",
    "\n",
    "\n",
    "# Sample prompts.\n",
    "prompts = [\n",
    "    \"Hello, my name is\",\n",
    "    \"The president of the United States is\",\n",
    "    \"The capital of France is\",\n",
    "    \"The future of AI is\",\n",
    "]\n",
    "\n",
    "# Create an LLM.\n",
    "# You should pass task=\"classify\" for classification models\n",
    "model = LLM(\n",
    "    model=\"/home/renchong/.cache/modelscope/hub/Qwen/Qwen3-4B-Instruct-2507\",\n",
    "    task=\"classify\",\n",
    "    enforce_eager=True,\n",
    ")\n",
    "\n",
    "# Generate logits. The output is a list of ClassificationRequestOutputs.\n",
    "outputs = model.classify(prompts)\n",
    "\n",
    "# Print the outputs.\n",
    "for prompt, output in zip(prompts, outputs):\n",
    "    probs = output.outputs.probs\n",
    "    probs_trimmed = ((str(probs[:16])[:-1] +\n",
    "                      \", ...]\") if len(probs) > 16 else probs)\n",
    "    print(f\"Prompt: {prompt!r} | \"\n",
    "          f\"Class Probabilities: {probs_trimmed} (size={len(probs)})\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "88e226c6",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'model' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mNameError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mmodel\u001b[49m\n",
      "\u001b[31mNameError\u001b[39m: name 'model' is not defined"
     ]
    }
   ],
   "source": [
    "model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "b129a022",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 测试system prompt\n",
    "openai_api_key = \"EMPTY\"\n",
    "openai_api_base = \"http://localhost:10085/v1\"\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=openai_api_key,\n",
    "    base_url=openai_api_base,\n",
    ")\n",
    "\n",
    "system_content_domain = system_content_domain_v3\n",
    "\n",
    "\n",
    "# content_domain = \"\"\n",
    "# content_semantic = \"\"\n",
    "#{\"role\": \"system\", \"content\": system_content_domain},\n",
    "#        extra_body={\n",
    "            # \"chat_template_kwargs\": {\"enable_thinking\": False},\n",
    "        # }, chat/completions\n",
    "def nlu_v1(query):\n",
    "    \n",
    "    chat_response_domain = client.chat.completions.create(\n",
    "        model=\"lora_domain_v1\",\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_content_domain},\n",
    "            {\"role\": \"user\", \"content\": query},\n",
    "        ],\n",
    "        max_tokens=16,\n",
    "        temperature=0.3,\n",
    "        extra_body={\"chat_template_kwargs\": {\"enable_thinking\": False}}\n",
    "\n",
    "    )\n",
    "\n",
    "    # return chat_response_domain\n",
    "    return f\"{chat_response_domain.choices[0].message.content}\"\n",
    "\n",
    "def nlu(query):\n",
    "    \n",
    "    chat_response_domain = client.chat.completions.create(\n",
    "        model=\"lora_domain\",\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_content_domain},\n",
    "            {\"role\": \"user\", \"content\": query},\n",
    "        ],\n",
    "        max_tokens=16,\n",
    "        temperature=0.3,\n",
    "        extra_body={\"chat_template_kwargs\": {\"enable_thinking\": False}}\n",
    "    )\n",
    "\n",
    "    # return chat_response_domain\n",
    "    return f\"{chat_response_domain.choices[0].message.content}\"\n",
    "\n",
    "def nlu_new(query, model_name):\n",
    "    \n",
    "    chat_response_domain = client.chat.completions.create(\n",
    "        model=model_name,\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_content_domain},\n",
    "            {\"role\": \"user\", \"content\": query},\n",
    "        ],\n",
    "        max_tokens=16,\n",
    "        temperature=0.3,\n",
    "        extra_body={\"chat_template_kwargs\": {\"enable_thinking\": False}}\n",
    "    )\n",
    "\n",
    "    # return chat_response_domain\n",
    "    return f\"{chat_response_domain.choices[0].message.content}\"\n",
    "\n",
    "messages_history=[\n",
    "            {\"role\": \"system\", \"content\": system_content_domain},\n",
    "        ],\n",
    "\n",
    "def chat(query, model_name):\n",
    "    messages_history.append({\"role\": \"user\", \"content\": query})\n",
    "    chat_response_domain = client.chat.completions.create(\n",
    "        model=model_name,\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_content_domain},\n",
    "            {\"role\": \"user\", \"content\": query},\n",
    "        ],\n",
    "        max_tokens=16,\n",
    "        temperature=0.3,\n",
    "        extra_body={\"chat_template_kwargs\": {\"enable_thinking\": False}}\n",
    "    )\n",
    "\n",
    "    # return chat_response_domain\n",
    "    return f\"{chat_response_domain.choices[0].message.content}\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "de8380fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "视频\n"
     ]
    }
   ],
   "source": [
    "query = \"播放周杰伦的视频\"\n",
    "# out1 = nlu_v1(query)\n",
    "# out = nlu(query)\n",
    "# print(f\"v1: {out1}\\nv2: {out}\")\n",
    "out = nlu_new(query, \"4B-2507\")\n",
    "\n",
    "print(f\"{out}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5183f92",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"test_query.txt\", 'r') as f:\n",
    "    for line in f:\n",
    "        query = line.strip()\n",
    "        out1 = nlu_new(query, \"lora_domain_v1\")\n",
    "        out2 = nlu_new(query, \"lora_domain\")\n",
    "        out_base = nlu_new(query, \"domain_model\")\n",
    "        print(f\"{query:<15}\\t {out_base:<18}\\t {out1:<18}\\t {out2:<15}\")\n",
    "        # {row[0]:<10} {row[1]:<5} {row[2]:<15}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4dc03def",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"test_query_1.txt\", 'r') as f:\n",
    "# with open(\"test_query.txt\", 'r') as f:\n",
    "    for line in f:\n",
    "        query = line.strip()\n",
    "        # out1 = nlu_new(query, \"8B_v2_epoch2\")\n",
    "        # out2 = nlu_new(query, \"8B_v2\")\n",
    "        out = nlu_new(query, \"4B-2507\")\n",
    "        out3 = nlu_new(query, \"4B-2507_epoch3\")\n",
    "        out2 = nlu_new(query, \"4B-2507_epoch2\")\n",
    "        # out_base = nlu_new(query, \"domain_model\")\n",
    "        # print(f\"{query:<15}\\t {out_base:<18}\\t {out1:<18}\\t {out2:<18}\")\n",
    "        print(f\"{query:<15}\\t {out:<18}\\t {out3:<18}\\t {out2:<18}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad0b1dff",
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "地图导航意图识别和槽位填充\n",
    "'''\n",
    "system_content = \"\"\"\n",
    "### 角色定义 ###\n",
    "你是一位导航意图文本语义理解专家，擅长根据用户输入的短文本对给定的语义槽位进行填充。\n",
    "\n",
    "### 核心技能 ###\n",
    "精准解析用户指令的语义意图\n",
    "准确匹配槽位，提取准确的槽值\n",
    "\n",
    "### 任务说明 ###\n",
    "理解每个槽位意义和可选项\n",
    "从文本提取信息并填充槽值\n",
    "\n",
    "### 槽位 ###\n",
    "text:\n",
    "origin:\n",
    "destination:\n",
    "strategy:默认|速度优先|费用优先|躲避拥堵|高速优先|不走高速|大路优先\n",
    "waypoints:\n",
    "\n",
    "### 格式示例 ###\n",
    "-输入:\n",
    "导航去南京南站\n",
    "\n",
    "-输出:\n",
    "text:导航去南京南站\n",
    "destination:南京南站\n",
    "strategy:默认\n",
    "\n",
    "### 格式示例 ###\n",
    "-输入:\n",
    "找一条最快的去南京南站的路\n",
    "\n",
    "-输出：\n",
    "text:找一条最快的去南京南站的路\n",
    "destination:南京南站\n",
    "strategy:速度优先\n",
    "\n",
    "### 格式示例 ###\n",
    "-输入:\n",
    "去南京南站的路顺便经过玄武湖\n",
    "\n",
    "-输出：\n",
    "text:找一条最快的去南京南站的路\n",
    "destination:南京南站\n",
    "strategy:速度优先\n",
    "waypoints:玄武湖\n",
    "\n",
    "### 关键规则 ###\n",
    "1. 只能在给定的槽位范围内填充,不能增加新的槽位\n",
    "2. 若槽位给出可选项,则只能在选项范围内选择,不能增加新的选项\n",
    "3. 若槽位没有给出可选项,则需要根据文本进行提取\n",
    "4. 提取内容要结合槽位的意义\n",
    "5. 若无法提取有效的槽值,则不输出该槽位\n",
    "\"\"\"\n",
    "\n",
    "openai_api_key = \"EMPTY\"\n",
    "openai_api_base = \"http://0.0.0.0:10085/v1\"\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=openai_api_key,\n",
    "    base_url=openai_api_base,\n",
    ")\n",
    "\n",
    "\n",
    "content=\"从南京南站到上海虹桥火车站途径镇江南站怎么走最快\"\n",
    "content=\"找一条南京到北京的路线，走高速，在济南停一下\"\n",
    "\n",
    "chat_response = client.chat.completions.create(\n",
    "    model=\"nlu_model\",\n",
    "    # model=\"lora_semantic\",\n",
    "    messages=[\n",
    "        {\"role\": \"system\", \"content\": system_content},\n",
    "        {\"role\": \"user\", \"content\": content},\n",
    "    ],\n",
    "    max_tokens=128,\n",
    "    extra_body={\n",
    "        \"chat_template_kwargs\": {\"enable_thinking\": False},\n",
    "    },\n",
    ")\n",
    "# print(\"Chat response:\", chat_response)\n",
    "print(f\"{chat_response.choices[0].message.content}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3a633109",
   "metadata": {},
   "outputs": [],
   "source": [
    "openai_api_key = \"EMPTY\"\n",
    "openai_api_base = \"http://0.0.0.0:10085/v1\"\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=openai_api_key,\n",
    "    base_url=openai_api_base,\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea78b9f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "两轮对话改写\n",
    "'''\n",
    "system_content = \"\"\"\n",
    "# 角色\n",
    "你是一个语义理解和文本优化专家。你的任务是将用户输入的文本，通过“指代消解”、“省略补全”和“多意图分句”等技术，改写成清晰、完整、流畅的版本。\n",
    "\n",
    "## 目标\n",
    "1. 依据历史输入、历史回答和当前输入，对当前输入文本进行改写。\n",
    "2. 改写后的文本要清晰、完整、流畅，且保持原文的核心意思和语气绝对不变。\n",
    "\n",
    "## 技能\n",
    "### 技能 1：根据用户输入进行多意图分句\n",
    "1. 仔细分析用户的历史输入和历史回答，挖掘出其中的实体信息，首先确认当前输入是否和历史输入有关联，若无关联则不进行改写，保持原文输出。\n",
    "2. 仔细分析用户的当前输入，明确其中的指代关系和省略内容。\n",
    "3. 运用丰富的语义理解经验，根据历史输入和历史回答，明确替换所有代词所指代的内容。\n",
    "4. 运用丰富的语义理解经验，根据历史输入和历史回答，补全句子中所有省略的成分，使每个句子语法完整。\n",
    "5. 确保每个子句意图明确，结构完整，保持原文的核心意思和语气绝对不变。\n",
    "\n",
    "## 工作流程\n",
    "1. 详细分析历史输入，提取其中的关键实体信息。\n",
    "2. 深入剖析当前输入，找出其中的指代关系和省略内容。\n",
    "3. 结合历史信息，对当前输入中的代词进行指代消解。\n",
    "4. 依据历史信息，补全当前输入中省略的成分。\n",
    "5. 检查改写后的句子，确保每个子句意图明确、结构完整且符合原文核心意思和语气。\n",
    "\n",
    "## 约束\n",
    "### 必须做的事\n",
    "1. 根据提供的历史输入，对当前的输入进行改写。\n",
    "2. 只输出改写后的内容。\n",
    "\n",
    "### 禁止做的事\n",
    "1. 不得改变原文的核心意思和语气。\n",
    "\n",
    "## 输出格式\n",
    "输出为清晰、完整、流畅的文本，以自然语言形式呈现，无多余格式要求。\n",
    "\n",
    "## 示例\n",
    "### 示例 1\n",
    "历史输入： “空调温度调高一点”\n",
    "当前输入： “放一首稻香”\n",
    "输入改写：“放一首稻香”\n",
    "\n",
    "### 示例 2\n",
    "历史输入： “空调温度调高一点”\n",
    "当前输入： “还是调低吧”\n",
    "输入改写：“空调温度还是调低吧”\n",
    "\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "# messages_history = [{\"role\": \"system\", \"content\": system_content},{\"role\": \"user\", \"content\":\" \"},{\"role\": \"assistant\", \"content\":\" \"},{\"role\": \"user\", \"content\":\"\"}]\n",
    "messages_history = [{\"role\": \"system\", \"content\": system_content},{\"role\": \"user\", \"content\":\" \"},{\"role\": \"user\", \"content\":\"\"}]\n",
    "\n",
    "def chat(query):\n",
    "    messages_history[-1][\"content\"] = query\n",
    "    print(f\"LOG:{messages_history}\")\n",
    "    chat_response = client.chat.completions.create(\n",
    "        model=\"base_model\",\n",
    "        messages=messages_history,\n",
    "        max_tokens=128,\n",
    "        extra_body={\n",
    "            \"chat_template_kwargs\": {\"enable_thinking\": False},\n",
    "        },\n",
    "    )\n",
    "    query_rewritten = chat_response.choices[0].message.content\n",
    "\n",
    "    chat_response = client.chat.completions.create(\n",
    "        model=\"4B-2507\",\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_content_domain_v3},\n",
    "            {\"role\": \"user\", \"content\": query_rewritten},\n",
    "        ],\n",
    "        max_tokens=128,\n",
    "        extra_body={\n",
    "            \"chat_template_kwargs\": {\"enable_thinking\": False},\n",
    "        },\n",
    "    )\n",
    "    res = chat_response.choices[0].message.content\n",
    "    messages_history[1][\"content\"] = query_rewritten\n",
    "    # messages_history[2][\"content\"] = res\n",
    "    # print(\"Chat response:\", chat_response)\n",
    "    return f\"query old: {query}\\nquery new: {query_rewritten}\\nanswer: {res}\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86795365",
   "metadata": {},
   "outputs": [],
   "source": [
    "res = chat(\"还是王力宏的吧\")\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a0aa9d0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "分句\n",
    "'''\n",
    "system_content = \"\"\"\n",
    "# 角色\n",
    "你是一个智能座舱车载语音助手的文本分句模块。你的核心任务是对用户输入的无标点或标点混乱的长句进行分句，将其切分为多个意图单一、结构完整的子句。\n",
    "\n",
    "## 任务\n",
    "精准识别用户输入文本中的多个意图边界，并将其划分为独立的子句，确保每个子句保留原意且通顺自然。\n",
    "\n",
    "## 工作流程\n",
    "1.  **语义分析**：首先理解输入文本的整体语义，识别其中独立的意图单元（如指令、询问、描述等）。\n",
    "2.  **边界识别**：基于意图切换、主语变更或动词结构等语言学特征，确定最佳的切分点。\n",
    "3.  **切分与格式化**：在切分点插入分隔符 `|`，将长句划分为多个子句。\n",
    "4.  **输出**：输出切分后的结果，确保不新增、删除或修改任何原始文本内容。\n",
    "\n",
    "## 示例\n",
    "输入： “太小声了几点了播放小说琅琊榜”\n",
    "输出： “太小声了|几点了|播放小说琅琊榜”\n",
    "\n",
    "输入： “打开空调今天天气怎么样声音大一点”\n",
    "输出： “打开空调|今天天气怎么样|声音大一点”\n",
    "\n",
    "输入： “打开车窗”\n",
    "输出： “打开车窗”\n",
    "\n",
    "输入： “打开车窗打开前排空调温度调高点还是关了吧后排也要”\n",
    "输出： “打开车窗|打开前排空调|温度调高点|还是关了吧|后排也要”\n",
    "\n",
    "## 关键规则\n",
    "- **保持原意绝对不变**：仅进行切分操作，不得添加、删除或修改任何字词。\n",
    "- **单一意图不切分**：若输入本身已是单一意图的短句，直接输出原句。\n",
    "- **分隔符使用**：所有子句之间必须用 `|` 符号分隔，首尾不得添加该符号或其他内容。\n",
    "- **容错处理**：对于口语中常见的重复、模糊或省略表达，也应尽量切分并保留原句结构（如：“那个空调嗯打开一下然后哦关闭车窗” → “那个空调嗯打开一下|然后哦关闭车窗”）。\n",
    "- **语气保留**：保留原始文本中的所有语气词、感叹词等（如：“啊”、“呀”、“哦”），不得删除或忽略。\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "def chat(query):\n",
    "    chat_response = client.chat.completions.create(\n",
    "        model=\"base_model\",\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_content},\n",
    "            {\"role\": \"user\", \"content\": query}\n",
    "        ],\n",
    "        max_tokens=128,\n",
    "        extra_body={\n",
    "            \"chat_template_kwargs\": {\"enable_thinking\": False},\n",
    "        },\n",
    "    )\n",
    "    query_rewritten = chat_response.choices[0].message.content\n",
    "\n",
    "\n",
    "    return f\"query old: {query}\\nquery new: {query_rewritten}\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9ad81e32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "query old: 打开前排空调\n",
      "query new: 打开前排空调\n"
     ]
    }
   ],
   "source": [
    "# res = chat(\"打开前排空调打开后排车窗温度调小点音量大一点播放周杰伦的稻香查一下明天的天气后天的呢\")\n",
    "res = chat(\"打开前排空调\")\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "31a66f1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#预定义好每个意图的词槽，让大模型做填空或选择，而不是直接生成\n",
    "\n",
    "semantic_tmp = {'空调-空调开关': 'object:空调|出风口\\noperate:打开|关闭|锁定|解锁\\nposition:',\n",
    " '空调-制冷制热': 'object:空调\\nmode:制冷|制热\\ndegree:最高|中等|最低|极速|自动\\noperate:打开|关闭\\nposition:',\n",
    " '空调-其他模式': 'mode:同步|除雾|除霜|除湿|循环|节能|舒适|强劲|空气净化|负离子|空气监测\\nobject:空调\\noperate:打开|关闭\\nposition:',\n",
    " '空调-风速调节': 'mode:风速\\ndegree:最高|中等|最低|高|低\\nobject:空调\\noperate:调成|调低|调高\\nposition:\\nvalue:',\n",
    " '空调-温度调节': 'mode:温度\\ndegree:最高|中等|最低|高|低\\nobject:空调\\noperate:调成|调高|调低\\nposition:\\nvalue:',\n",
    " '空调-吹风模式': 'mode:吹风\\nobject:空调\\noperate:打开|关闭|调成\\nposition:',\n",
    " '空调-出风口调节': 'object:出风口\\noperate:调成\\nposition:\\nplace:上|下|左|右|中',\n",
    " '系统设置-打开和关闭页面': 'mode:页面\\nobject:\\noperate:打开|关闭',\n",
    " '系统设置-蓝牙和网络': 'object:蓝牙|wifi|蜂窝移动数据|热点\\noperate:打开|关闭|连接|断连',\n",
    " '系统设置-声音': 'object:\\noperate:调高|调低|静音|查询|打开|关闭\\nvalue:\\nposition:',\n",
    " '系统设置-屏幕': 'mode:亮度\\ndegree:最高|最低|中等\\nobject:屏幕|仪表\\noperate:调高|调低|调成\\nvalue:\\nposition:',\n",
    " '系统设置-壁纸': 'mode:壁纸\\ntag:',\n",
    " '车辆控制-车窗': 'object:车窗|车窗锁\\noperate:打开|关闭|暂停|调大|调小|调成\\nposition:\\nvalue:',\n",
    " '车辆控制-天窗': 'object:天窗\\noperate:打开|关闭|暂停|调大|调小|调成\\nposition:\\nvalue:',\n",
    " '车辆控制-遮阳帘': 'object:遮阳帘\\noperate:打开|关闭|暂停|调大|调小|调成\\nposition:\\nvalue:',\n",
    " '车辆控制-座椅加热': 'object:座椅|座椅靠背|座椅坐垫\\nmode:加热\\noperate:打开|关闭|暂停|调大|调小|调成\\ndegree:最高|最低|高|中|低|自动\\nposition:\\nvalue:',\n",
    " '车辆控制-座椅通风': 'object:座椅|座椅靠背|座椅坐垫\\nmode:通风\\noperate:打开|关闭|暂停|调高|调低|调成\\ndegree:最大|最小|高|中|低|自动\\nposition:\\nvalue:',\n",
    " '车辆控制-座椅按摩': 'object:座椅\\nmode:按摩\\nmodeValue:\\noperate:打开|关闭|暂停|调高|调低|调成\\ndegree:最高|最低|高|中|低|自动\\nposition:\\nvalue:',\n",
    " '车辆控制-座椅调节': 'object:座椅|座椅后背|座椅靠背\\nmode:座椅调节\\noperate:前进|后退|向上|向下|向左|向右|调成\\ndegree:最前|最后\\nposition:\\nvalue:',\n",
    " '车辆控制-车门控制': 'object:车门\\noperate:打开|关闭|暂停|调大|调小\\nposition:',\n",
    " '车辆控制-其他控制': 'object:\\nmode:\\noperate:打开|关闭|暂停|调高|调低|调成|向左|向右\\ndegree:最高|最低|手动\\nvalue:\\nposition:',\n",
    " '车辆信息查询':'object:\\noperate:查询',\n",
    " '电话-呼叫':'name:\\ncode:\\n',\n",
    " '电话-指令':'operate:',\n",
    " '应用':'operate:打开|关闭\\nobject:',\n",
    " '地图-导航':'origin:\\ndestination:\\nstrategy:默认|速度优先|费用优先|躲避拥堵|高速优先|不走高速|大路优先\\nwaypoints:',\n",
    " '地图-搜索':'keywords:\\nregion:',\n",
    " '地图-指令':'operate:',\n",
    " '天气-查询':'object:天气|晴|多云|阴|雨|雾霾|雪|气温\\noperate:查询\\ncity:\\ntime:',\n",
    " '音乐-播放歌曲':'operate:播放\\nsong:\\nauthor:\\nsource:\\ntag:\\nalbum:',\n",
    " '音乐-歌曲控制':'operate:切歌|播放|停止|向上切歌|向下切歌|重新播放\\nmode:顺序|循环|随机|单曲循环',\n",
    " '视频-视频播放':'object:视频\\noperate:打开|查询|播放\\nauthor:\\ntitle:\\ntag:\\nsource:',\n",
    " '视频-视频控制':'object:视频\\noperate:暂停|播放|向下切换|收藏|取消收藏',\n",
    " }\n",
    "\n",
    "domain_en_dict = {'车辆控制': 'carControl',\n",
    " '空调': 'airControl',\n",
    " '系统设置': 'cmd',\n",
    " '地图': 'mapU',\n",
    " '音乐': 'musicX',\n",
    " '电话': 'telephone',\n",
    " '电台': 'radio',\n",
    " '视频': 'video',\n",
    " '天气': 'weather',\n",
    " '新闻': 'news',\n",
    " '火车': 'train',\n",
    " '航班': 'flight',\n",
    " '应用': 'app',\n",
    " '日程': 'scheduleX',\n",
    " '车辆信息查询': 'vehicleInfo',\n",
    " '股票': 'stock',\n",
    " '其他': 'other'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ed5c61b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "544ad3d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "from openai import OpenAI\n",
    "# Set OpenAI's API key and API base to use vLLM's API server.\n",
    "openai_api_key = \"EMPTY\"\n",
    "openai_api_base = \"http://localhost:10085/v1\"\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=openai_api_key,\n",
    "    base_url=openai_api_base,\n",
    ")\n",
    "\n",
    "system_content_domain = system_content_domain_v3\n",
    "\n",
    "\n",
    "system_content_semantic = \n",
    "\n",
    "# content_domain = \"\"\n",
    "# content_semantic = \"\"\n",
    "\n",
    "def nlu(query):\n",
    "        \n",
    "# Step 1: 领域和意图识别\n",
    "    domain_response = client.chat.completions.create(\n",
    "        model='lora_domain',\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_content_domain},\n",
    "            {\"role\": \"user\", \"content\": query},\n",
    "        ],\n",
    "        temperature=0.3,\n",
    "        max_tokens=16,\n",
    "        extra_body={\"chat_template_kwargs\": {\"enable_thinking\": False}}\n",
    "    )\n",
    "    \n",
    "    domain_intent = domain_response.choices[0].message.content\n",
    "    domain, intent = domain_intent.split(\"-\", 1) if \"-\" in domain_intent else (domain_intent, domain_intent)\n",
    "    print(f\"domain_intent:{domain_intent}\")\n",
    "    if domain in domain_en_dict:\n",
    "        domain_en = domain_en_dict[domain]\n",
    "    else:\n",
    "        domain_en = \"other\"\n",
    "\n",
    "    result = {\"domain\": domain_en, \"intent\": intent, \"text\": query, \"slot\": {}}\n",
    "\n",
    "    # Step 2: 检查是否需要语义解析\n",
    "    if domain_intent not in semantic_tmp:\n",
    "        # result=f\"domain:{domain}\\nintent:{intent}\\ntext:{query}\"\n",
    "        return result\n",
    "        \n",
    "    \n",
    "    # Step 3: 语义解析处理\n",
    "    semantic_content = f\"domain:{domain}\\nintent:{intent}\\ntext:{query}\\n{semantic_tmp[domain_intent]}\"\n",
    "    semantic_response = client.chat.completions.create(\n",
    "        model='lora_semantic',\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_content_semantic},\n",
    "            {\"role\": \"user\", \"content\": semantic_content},\n",
    "        ],\n",
    "        temperature=0.3,\n",
    "        max_tokens=128,\n",
    "        extra_body={\"chat_template_kwargs\": {\"enable_thinking\": False}}\n",
    "    )\n",
    "    slot = {}\n",
    "    for pair in semantic_response.choices[0].message.content.strip().split('\\n'):  # 按行拆分\n",
    "        key, value = pair.split(':', 1)        # 仅分割第一个冒号，避免值中含冒号\n",
    "        slot[key.strip()] = value.strip() \n",
    "    result[\"slot\"] = slot\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd74b9ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "out = nlu(\"导航到北京西站,在济南停一下\")\n",
    "print(f\"{out}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b313c8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from openai import OpenAI\n",
    "# Set OpenAI's API key and API base to use vLLM's API server.\n",
    "openai_api_key = \"EMPTY\"\n",
    "openai_api_base = \"http://localhost:10086/v1\"\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=openai_api_key,\n",
    "    base_url=openai_api_base,\n",
    ")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01ce9bdc",
   "metadata": {},
   "outputs": [],
   "source": [
    "{\"result\":\n",
    " {\"domain\":\"空调\",\n",
    "  \"intent\":\"温度调节\",\n",
    "  \"text\":\"空调温度调高十度\",\n",
    "  \"slot\":{\"mode\":\"温度\",\"operate\":\"调高\",\"value\":\"10\"}}}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f5fb8cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "YSTEM_CONTENT_REWRITE = \"\"\"\n",
    "# 角色\n",
    "你是一名车载语音助手的语义改写模块，专门负责对用户输入进行指代消解和省略补全，使其成为完整、清晰、自然的语句。\n",
    "\n",
    "## 任务描述\n",
    "- 根据提供的多轮对话历史，理解上下文。\n",
    "- 对最新一轮用户输入进行改写，仅当存在指代不清或省略成分时进行补全。\n",
    "- 确保改写后的语句意图明确、结构完整，且与上下文保持一致。\n",
    "\n",
    "## 工作流程\n",
    "1. 分析对话历史，识别关键实体（如对象、动作、时间等）。\n",
    "2. 检查当前输入中是否存在代词（如那、这、他等）、省略或上下文依赖表达。\n",
    "3. 若有指代或省略，则依据历史信息进行补全（优先使用最近上下文）。\n",
    "4. 若当前输入已完整或无上下文依赖，则直接输出原句。\n",
    "\n",
    "## 关键规则\n",
    "- 当前输入与历史对话存在语义关联时进行改写。\n",
    "- 若指代不明确，默认使用最近提及的合理实体进行补全。\n",
    "- 输出应为纯文本，不带标点。\n",
    "\n",
    "\n",
    "## 输入格式\n",
    "对话历史以列表形式提供，每轮包含用户输入和助手响应（若有）。例如：\n",
    "- user: \"打开前排车窗\"\n",
    "- assistant: \"打开前排车窗\"\n",
    "- user: \"后排也要\"\n",
    "\n",
    "## 示例\n",
    "user: 打开前排车窗\n",
    "assistant: 打开前排车窗\n",
    "user: 后排也要\n",
    "assistant: 打开后排车窗\n",
    "\n",
    "user: 明天南京的天气怎么样\n",
    "assistant: 明天南京的天气怎么样\n",
    "user: 后天呢\n",
    "assistant: 后天南京的天气怎么样\n",
    "\n",
    "user: 播放周杰伦的稻香\n",
    "assistant: 播放周杰伦的稻香\n",
    "user: 介绍一下这个歌手\n",
    "assistant: 介绍一下周杰伦\n",
    "user: 播放他的其他歌\n",
    "assistant: 播放周杰伦的其他歌\n",
    "\n",
    "user: 南京的天气怎么样\n",
    "assistant: 南京的天气怎么样\n",
    "user: 导航去那里\n",
    "assistant: 导航去南京\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af7445c7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "91bc638f",
   "metadata": {},
   "outputs": [],
   "source": [
    "[\n",
    "  {\n",
    "    \"input\": {\n",
    "      \"text\": \"把空调风量调大三挡\",\n",
    "      \"domain\": \"空调\",\n",
    "      \"intent\": \"风速调节\",\n",
    "      \"mode\": \"风速\",\n",
    "      \"degree\": \"最高|中等|最低|高|低\",\n",
    "      \"object\": \"空调\",\n",
    "      \"operate\": \"调成|调低|调高\",\n",
    "      \"position\": \"\",\n",
    "      \"value\": \"\"\n",
    "    },\n",
    "    \"output\": {\n",
    "      \"text\": \"把空调风量调大三挡\",\n",
    "      \"domain\": \"空调\",\n",
    "      \"intent\": \"风速调节\",\n",
    "      \"mode\": \"风速\",\n",
    "      \"object\": \"空调\",\n",
    "      \"operate\": \"调高\",\n",
    "      \"value\": \"3\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"input\": {\n",
    "      \"text\": \"明天南京有雨吗\",\n",
    "      \"domain\": \"天气\",\n",
    "      \"intent\": \"查询\",\n",
    "      \"type\": \"天气|晴|多云|阴|雨|雾霾|雪|气温\",\n",
    "      \"location\": \"\",\n",
    "      \"time\": \"\"\n",
    "    },\n",
    "    \"output\": {\n",
    "      \"text\": \"明天南京有雨吗\",\n",
    "      \"domain\": \"天气\",\n",
    "      \"intent\": \"查询\",\n",
    "      \"object\": \"雨\",\n",
    "      \"city\": \"南京\",\n",
    "      \"time\": \"明天\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"input\": {\n",
    "      \"text\": \"去南京南站顺便路过玄武湖\",\n",
    "      \"domain\": \"地图\",\n",
    "      \"intent\": \"导航\",\n",
    "      \"origin\": \"\",\n",
    "      \"destination\": \"\",\n",
    "      \"strategy\": \"默认|速度优先|费用优先|躲避拥堵|高速优先|不走高速|大路优先\",\n",
    "      \"waypoints\": \"\"\n",
    "    },\n",
    "    \"output\": {\n",
    "      \"text\": \"去南京南站顺便路过玄武湖\",\n",
    "      \"domain\": \"地图\",\n",
    "      \"intent\": \"导航\",\n",
    "      \"destination\": \"南京南站\",\n",
    "      \"strategy\": \"默认\",\n",
    "      \"waypoints\": \"玄武湖\"\n",
    "    }\n",
    "  },\n",
    "  {\n",
    "    \"input\": {\n",
    "      \"text\": \"从南京南站去镇江南站最快的路\",\n",
    "      \"domain\": \"地图\",\n",
    "      \"intent\": \"导航\",\n",
    "      \"origin\": \"\",\n",
    "      \"destination\": \"\",\n",
    "      \"strategy\": \"默认|速度优先|费用优先|躲避拥堵|高速优先|不走高速|大路优先\",\n",
    "      \"waypoints\": \"\"\n",
    "    },\n",
    "    \"output\": {\n",
    "      \"text\": \"从南京南站去镇江南站最快的路\",\n",
    "      \"domain\": \"地图\",\n",
    "      \"intent\": \"导航\",\n",
    "      \"origin\": \"南京南站\",\n",
    "      \"destination\": \"镇江南站\",\n",
    "      \"strategy\": \"速度优先\"\n",
    "    }\n",
    "  }\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e463e819",
   "metadata": {},
   "outputs": [],
   "source": [
    "semantic_tmp = {'空调-空调开关': 'object:空调|出风口\\noperate:打开|关闭|锁定|解锁\\nposition:',\n",
    " '空调-制冷制热': 'object:空调\\nmode:制冷|制热\\ndegree:最高|中等|最低|极速|自动\\noperate:打开|关闭\\nposition:',\n",
    " '空调-其他模式': 'mode:同步|除雾|除霜|除湿|循环|节能|舒适|强劲|空气净化|负离子|空气监测\\nobject:空调\\noperate:打开|关闭\\nposition:',\n",
    " '空调-风速调节': 'mode:风速\\ndegree:最高|中等|最低|高|低\\nobject:空调\\noperate:调成|调低|调高\\nposition:\\nvalue:',\n",
    " '空调-温度调节': 'mode:温度\\ndegree:最高|中等|最低|高|低\\nobject:空调\\noperate:调成|调高|调低\\nposition:\\nvalue:',\n",
    " '空调-吹风模式': 'mode:吹风\\nobject:空调\\noperate:打开|关闭|调成\\nposition:',\n",
    " '空调-出风口调节': 'object:出风口\\noperate:调成\\nposition:\\nplace:上|下|左|右|中',\n",
    " '系统设置-打开和关闭页面': 'mode:页面\\nobject:\\noperate:打开|关闭',\n",
    " '系统设置-蓝牙和网络': 'object:蓝牙|wifi|蜂窝移动数据|热点\\noperate:打开|关闭|连接|断连',\n",
    " '系统设置-声音': 'object:\\noperate:调高|调低|静音|查询|打开|关闭\\nvalue:\\nposition:',\n",
    " '系统设置-屏幕': 'mode:亮度\\ndegree:最高|最低|中等\\nobject:屏幕|仪表\\noperate:调高|调低|调成\\nvalue:\\nposition:',\n",
    " '系统设置-壁纸': 'mode:壁纸\\ntag:',\n",
    " '车辆控制-车窗': 'object:车窗|车窗锁\\noperate:打开|关闭|暂停|调大|调小|调成\\nposition:\\nvalue:',\n",
    " '车辆控制-天窗': 'object:天窗\\noperate:打开|关闭|暂停|调大|调小|调成\\nposition:\\nvalue:',\n",
    " '车辆控制-遮阳帘': 'object:遮阳帘\\noperate:打开|关闭|暂停|调大|调小|调成\\nposition:\\nvalue:',\n",
    " '车辆控制-座椅加热': 'object:座椅|座椅靠背|座椅坐垫\\nmode:加热\\noperate:打开|关闭|暂停|调大|调小|调成\\ndegree:最高|最低|高|中|低|自动\\nposition:\\nvalue:',\n",
    " '车辆控制-座椅通风': 'object:座椅|座椅靠背|座椅坐垫\\nmode:通风\\noperate:打开|关闭|暂停|调高|调低|调成\\ndegree:最大|最小|高|中|低|自动\\nposition:\\nvalue:',\n",
    " '车辆控制-座椅按摩': 'object:座椅\\nmode:按摩\\nmodeValue:\\noperate:打开|关闭|暂停|调高|调低|调成\\ndegree:最高|最低|高|中|低|自动\\nposition:\\nvalue:',\n",
    " '车辆控制-座椅调节': 'object:座椅|座椅后背|座椅靠背\\nmode:座椅调节\\noperate:前进|后退|向上|向下|向左|向右|调成\\ndegree:最前|最后\\nposition:\\nvalue:',\n",
    " '车辆控制-车门控制': 'object:车门\\noperate:打开|关闭|暂停|调大|调小\\nposition:',\n",
    " '车辆控制-其他控制': 'object:\\nmode:\\noperate:打开|关闭|暂停|调高|调低|调成|向左|向右\\ndegree:最高|最低|手动\\nvalue:\\nposition:',\n",
    " '车辆信息查询':'object:\\noperate:查询',\n",
    " '电话-呼叫':'name:\\nnumber:\\n',\n",
    " '电话-指令':'operate:',\n",
    " '应用':'object:\\noperate:打开|关闭',\n",
    " '导航-导航':'origin:\\ndestination:\\nstrategy:默认|速度优先|费用优先|躲避拥堵|高速优先|不走高速|大路优先\\nwaypoints:',\n",
    " '导航-搜索':'keywords:\\nregion:',\n",
    " '导航-指令':'operate:',\n",
    " '天气-查询':'object:天气|晴|多云|阴|雨|雾霾|雪|气温\\noperate:查询\\ncity:\\ntime:',\n",
    " '音乐-播放歌曲':'operate:播放\\nsong:\\nauthor:\\nsource:\\ntag:\\nalbum:',\n",
    " '音乐-歌曲控制':'operate:切歌|播放|停止|向上切歌|向下切歌|重新播放\\nmode:顺序|循环|随机|单曲循环',\n",
    " '视频-视频播放':'object:视频\\noperate:打开|查询|播放\\nauthor:\\ntitle:\\ntag:\\nsource:',\n",
    " '视频-视频控制':'object:视频\\noperate:暂停|播放|向下切换|收藏|取消收藏',\n",
    " }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "82b3ed1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "semantic_dict = {\n",
    "  \"空调-空调开关\": {\n",
    "    \"object\": [\"空调\", \"出风口\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"锁定\", \"解锁\"],\n",
    "    \"position\": \"\"\n",
    "  },\n",
    "  \"空调-制冷制热\": {\n",
    "    \"object\": [\"空调\"],\n",
    "    \"mode\": [\"制冷\", \"制热\"],\n",
    "    \"degree\": [\"最高\", \"中等\", \"最低\", \"极速\", \"自动\"],\n",
    "    \"operate\": [\"打开\", \"关闭\"],\n",
    "    \"position\": \"\"\n",
    "  },\n",
    "  \"空调-其他模式\": {\n",
    "    \"mode\": [\"同步\", \"除雾\", \"除霜\", \"除湿\", \"循环\", \"节能\", \"舒适\", \"强劲\", \"空气净化\", \"负离子\", \"空气监测\"],\n",
    "    \"object\": [\"空调\"],\n",
    "    \"operate\": [\"打开\", \"关闭\"],\n",
    "    \"position\": \"\"\n",
    "  },\n",
    "  \"空调-风速调节\": {\n",
    "    \"mode\": [\"风速\"],\n",
    "    \"degree\": [\"最高\", \"中等\", \"最低\", \"高\", \"低\"],\n",
    "    \"object\": [\"空调\"],\n",
    "    \"operate\": [\"调成\", \"调低\", \"调高\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"空调-温度调节\": {\n",
    "    \"mode\": [\"温度\"],\n",
    "    \"degree\": [\"最高\", \"中等\", \"最低\", \"高\", \"低\"],\n",
    "    \"object\": [\"空调\"],\n",
    "    \"operate\": [\"调成\", \"调高\", \"调低\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"空调-吹风模式\": {\n",
    "    \"mode\": [\"吹风\"],\n",
    "    \"object\": [\"空调\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"调成\"],\n",
    "    \"position\": \"\"\n",
    "  },\n",
    "  \"系统设置-打开和关闭页面\": {\n",
    "    \"mode\": [\"页面\"],\n",
    "    \"object\": [],\n",
    "    \"operate\": [\"打开\", \"关闭\"]\n",
    "  },\n",
    "  \"系统设置-蓝牙和网络\": {\n",
    "    \"object\": [\"蓝牙\", \"wifi\", \"蜂窝移动数据\", \"热点\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"连接\", \"断连\"]\n",
    "  },\n",
    "  \"系统设置-声音\": {\n",
    "    \"object\": [],\n",
    "    \"operate\": [\"调高\", \"调低\", \"静音\", \"查询\", \"打开\", \"关闭\"],\n",
    "    \"value\": \"\",\n",
    "    \"position\": \"\"\n",
    "  },\n",
    "  \"系统设置-屏幕\": {\n",
    "    \"mode\": [\"亮度\"],\n",
    "    \"degree\": [\"最高\", \"最低\", \"中等\"],\n",
    "    \"object\": [\"屏幕\", \"仪表\"],\n",
    "    \"operate\": [\"调高\", \"调低\", \"调成\"],\n",
    "    \"value\": \"\",\n",
    "    \"position\": \"\"\n",
    "  },\n",
    "  \"系统设置-壁纸\": {\n",
    "    \"mode\": [\"壁纸\"],\n",
    "    \"tag\": \"\"\n",
    "  },\n",
    "  \"车辆控制-车窗\": {\n",
    "    \"object\": [\"车窗\", \"车窗锁\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"车辆控制-天窗\": {\n",
    "    \"object\": [\"天窗\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"车辆控制-遮阳帘\": {\n",
    "    \"object\": [\"遮阳帘\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"车辆控制-座椅加热\": {\n",
    "    \"object\": [\"座椅\", \"座椅靠背\", \"座椅坐垫\"],\n",
    "    \"mode\": [\"加热\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"],\n",
    "    \"degree\": [\"最高\", \"最低\", \"高\", \"中\", \"低\", \"自动\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"车辆控制-座椅通风\": {\n",
    "    \"object\": [\"座椅\", \"座椅靠背\", \"座椅坐垫\"],\n",
    "    \"mode\": [\"通风\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\"],\n",
    "    \"degree\": [\"最大\", \"最小\", \"高\", \"中\", \"低\", \"自动\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"车辆控制-座椅按摩\": {\n",
    "    \"object\": [\"座椅\"],\n",
    "    \"mode\": [\"按摩\"],\n",
    "    \"modeValue\": \"\",\n",
    "    \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\"],\n",
    "    \"degree\": [\"最高\", \"最低\", \"高\", \"中\", \"低\", \"自动\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"车辆控制-座椅调节\": {\n",
    "    \"object\": [\"座椅\", \"座椅后背\", \"座椅靠背\"],\n",
    "    \"mode\": [\"座椅调节\"],\n",
    "    \"operate\": [\"前进\", \"后退\", \"向上\", \"向下\", \"向左\", \"向右\", \"调成\"],\n",
    "    \"degree\": [\"最前\", \"最后\"],\n",
    "    \"position\": \"\",\n",
    "    \"value\": \"\"\n",
    "  },\n",
    "  \"车辆控制-车门控制\": {\n",
    "    \"object\": [\"车门\"],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\"],\n",
    "    \"position\": \"\"\n",
    "  },\n",
    "  \"车辆控制-其他控制\": {\n",
    "    \"object\": [],\n",
    "    \"mode\": [],\n",
    "    \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\", \"向左\", \"向右\"],\n",
    "    \"degree\": [\"最高\", \"最低\", \"手动\"],\n",
    "    \"value\": \"\",\n",
    "    \"position\": \"\"\n",
    "  },\n",
    "  \"车辆信息查询\": {\n",
    "    \"object\": [],\n",
    "    \"operate\": [\"查询\"]\n",
    "  },\n",
    "  \"电话-呼叫\": {\n",
    "    \"name\": \"\",\n",
    "    \"number\": \"\"\n",
    "  },\n",
    "  \"电话-指令\": {\n",
    "    \"operate\": \"\"\n",
    "  },\n",
    "  \"应用\": {\n",
    "    \"object\": \"\",\n",
    "    \"operate\": [\"打开\", \"关闭\"]\n",
    "  },\n",
    "  \"导航-导航\": {\n",
    "    \"origin\": \"\",\n",
    "    \"destination\": \"\",\n",
    "    \"strategy\": [\"默认\", \"速度优先\", \"费用优先\", \"躲避拥堵\", \"高速优先\", \"不走高速\", \"大路优先\"],\n",
    "    \"waypoints\": \"\"\n",
    "  },\n",
    "  \"导航-搜索\": {\n",
    "    \"keywords\": \"\",\n",
    "    \"region\": \"\"\n",
    "  },\n",
    "  \"导航-指令\": {\n",
    "    \"operate\": \"\"\n",
    "  },\n",
    "  \"天气-查询\": {\n",
    "    \"object\": [\"天气\", \"晴\", \"多云\", \"阴\", \"雨\", \"雾霾\", \"雪\", \"气温\"],\n",
    "    \"operate\": [\"查询\"],\n",
    "    \"city\": \"\",\n",
    "    \"time\": \"\"\n",
    "  },\n",
    "  \"音乐-播放歌曲\": {\n",
    "    \"operate\": [\"播放\"],\n",
    "    \"song\": \"\",\n",
    "    \"author\": \"\",\n",
    "    \"source\": \"\",\n",
    "    \"tag\": \"\",\n",
    "    \"album\": \"\"\n",
    "  },\n",
    "  \"音乐-歌曲控制\": {\n",
    "    \"operate\": [\"切歌\", \"播放\", \"停止\", \"向上切歌\", \"向下切歌\", \"重新播放\"],\n",
    "    \"mode\": [\"顺序\", \"循环\", \"随机\", \"单曲循环\"]\n",
    "  },\n",
    "  \"视频-视频播放\": {\n",
    "    \"object\": [\"视频\"],\n",
    "    \"operate\": [\"打开\", \"查询\", \"播放\"],\n",
    "    \"author\": \"\",\n",
    "    \"title\": \"\",\n",
    "    \"tag\": \"\",\n",
    "    \"source\": \"\"\n",
    "  },\n",
    "  \"视频-视频控制\": {\n",
    "    \"object\": [\"视频\"],\n",
    "    \"operate\": [\"暂停\", \"播放\", \"向下切换\", \"收藏\", \"取消收藏\"]\n",
    "  }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e78d116e",
   "metadata": {},
   "outputs": [],
   "source": [
    "semantic_dict = {\n",
    "    \"airControl\": {\n",
    "        \"空调开关\": {\n",
    "            \"object\": [\"空调\", \"出风口\"],\n",
    "            \"operate\": [\"打开\", \"关闭\", \"锁定\", \"解锁\"],\n",
    "            \"position\": \"\"\n",
    "        },\n",
    "        \"制冷制热\": {\n",
    "            \"object\": \"空调\",\n",
    "            \"mode\": [\"制冷\", \"制热\"],\n",
    "            \"degree\": [\"最高\", \"中等\", \"最低\", \"极速\", \"自动\"],\n",
    "            \"operate\": [\"打开\", \"关闭\"],\n",
    "            \"position\": \"\"\n",
    "        },\n",
    "        \"其他模式\": {\n",
    "            \"mode\": [\"同步\", \"除雾\", \"除霜\", \"除湿\", \"循环\", \"节能\", \"舒适\", \"强劲\", \"空气净化\", \"负离子\", \"空气监测\"],\n",
    "            \"object\": \"空调\",\n",
    "            \"operate\": [\"打开\", \"关闭\"],\n",
    "            \"position\": \"\"\n",
    "        },\n",
    "        \"风速调节\": {\n",
    "            \"mode\": \"风速\",\n",
    "            \"degree\": [\"最高\", \"中等\", \"最低\", \"高\", \"低\"],\n",
    "            \"object\": [\"空调\"],\n",
    "            \"operate\": [\"调成\", \"调低\", \"调高\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"温度调节\": {\n",
    "            \"mode\": \"温度\",\n",
    "            \"degree\": [\"最高\", \"中等\", \"最低\", \"高\", \"低\"],\n",
    "            \"object\": [\"空调\"],\n",
    "            \"operate\": [\"调成\", \"调高\", \"调低\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"吹风模式\": {\n",
    "            \"mode\": \"吹风\",\n",
    "            \"object\": \"空调\",\n",
    "            \"operate\": [\"打开\", \"关闭\", \"调成\"],\n",
    "            \"position\": \"\"\n",
    "        }\n",
    "    },\n",
    "    \"cmd\": {\n",
    "        \"打开和关闭页面\": {\n",
    "            \"mode\": \"页面\",\n",
    "            \"object\": \"\",\n",
    "            \"operate\": [\"打开\", \"关闭\"]\n",
    "        },\n",
    "        \"蓝牙和网络\": {\n",
    "            \"object\": [\"蓝牙\", \"wifi\", \"蜂窝移动数据\", \"热点\"],\n",
    "            \"operate\": [\"打开\", \"关闭\", \"连接\", \"断连\"]\n",
    "        },\n",
    "        \"声音\": {\n",
    "            \"object\": \"\",\n",
    "            \"operate\": [\"调高\", \"调低\", \"静音\", \"查询\", \"打开\", \"关闭\"],\n",
    "            \"value\": \"\",\n",
    "            \"position\": \"\"\n",
    "        },\n",
    "        \"屏幕\": {\n",
    "            \"mode\": \"亮度\",\n",
    "            \"degree\": [\"最高\", \"最低\", \"中等\"],\n",
    "            \"object\": [\"屏幕\", \"仪表\"],\n",
    "            \"operate\": [\"调高\", \"调低\", \"调成\"],\n",
    "            \"value\": \"\",\n",
    "            \"position\": \"\"\n",
    "        },\n",
    "        \"主题壁纸\": {\n",
    "            \"mode\": [\"主题\", \"壁纸\"],\n",
    "            \"tag\": \"\"\n",
    "        },\n",
    "    },\n",
    "    \"carControl\": {\n",
    "        \"车窗\": {\n",
    "            \"object\": [\"车窗\", \"车窗锁\"],\n",
    "            \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"天窗\": {\n",
    "            \"object\": \"天窗\",\n",
    "            \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"遮阳帘\": {\n",
    "            \"object\": \"遮阳帘\",\n",
    "            \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"座椅加热\": {\n",
    "            \"object\": [\"座椅\", \"座椅靠背\", \"坐垫\"],\n",
    "            \"mode\": \"加热\",\n",
    "            \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"],\n",
    "            \"degree\": [\"最高\", \"最低\", \"高\", \"中\", \"低\", \"自动\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"座椅通风\": {\n",
    "            \"object\": [\"座椅\", \"靠背\", \"坐垫\"],\n",
    "            \"mode\": \"通风\",\n",
    "            \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\"],\n",
    "            \"degree\": [\"最大\", \"最小\", \"高\", \"中\", \"低\", \"自动\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"座椅按摩\": {\n",
    "            \"object\": [\"座椅\", \"靠背\", \"坐垫\"],\n",
    "            \"mode\": \"按摩\",\n",
    "            \"modeValue\": \"\",\n",
    "            \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\"],\n",
    "            \"degree\": [\"最高\", \"最低\", \"高\", \"中\", \"低\", \"自动\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"座椅调节\": {\n",
    "            \"object\": [\"座椅\", \"座椅后背\", \"座椅靠背\"],\n",
    "            \"mode\": [\"座椅调节\"],\n",
    "            \"operate\": [\"前进\", \"后退\", \"向上\", \"向下\", \"向左\", \"向右\", \"调成\"],\n",
    "            \"degree\": [\"最前\", \"最后\"],\n",
    "            \"position\": \"\",\n",
    "            \"value\": \"\"\n",
    "        },\n",
    "        \"车门控制\": {\n",
    "            \"object\": \"车门\",\n",
    "            \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\"],\n",
    "            \"position\": \"\"\n",
    "        },\n",
    "        \"其他控制\": {\n",
    "            \"object\": \"\",\n",
    "            \"mode\": \"[]\",\n",
    "            \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\", \"向左\", \"向右\"],\n",
    "            \"degree\": [\"最高\", \"最低\", \"手动\"],\n",
    "            \"value\": \"\",\n",
    "            \"position\": \"\"\n",
    "        },\n",
    "    },\n",
    "    \"vehicleInfo\":{\n",
    "        \"车辆信息查询\": {\n",
    "            \"object\": \"\",\n",
    "            \"operate\": \"查询\"\n",
    "        },\n",
    "    },\n",
    "    \"telephone\":{\n",
    "        \"电话-呼叫\": {\n",
    "            \"name\": \"\",\n",
    "            \"number\": \"\"\n",
    "        },\n",
    "        \"电话-指令\": {\n",
    "            \"operate\": \"\"\n",
    "        },\n",
    "    },\n",
    "    \"app\":{\n",
    "        \"app\": {\n",
    "            \"object\": \"\",\n",
    "            \"operate\": [\"打开\", \"关闭\"]\n",
    "        },\n",
    "    },\n",
    "    \"mapU\":{\n",
    "        \"导航\": {\n",
    "            \"origin\": \"\",\n",
    "            \"destination\": \"\",\n",
    "            \"strategy\": [\"默认\", \"速度优先\", \"费用优先\", \"躲避拥堵\", \"高速优先\", \"不走高速\", \"大路优先\"],\n",
    "            \"waypoints\": \"\"\n",
    "        },\n",
    "        \"搜索\": {\n",
    "            \"keywords\": \"\",\n",
    "            \"region\": \"\"\n",
    "        },\n",
    "    },\n",
    "    \"weather\":{\n",
    "        \"查询\": {\n",
    "            \"object\": [\"天气\", \"晴\", \"多云\", \"阴\", \"雨\", \"雾霾\", \"雪\", \"气温\"],\n",
    "            \"operate\": \"查询\",\n",
    "            \"city\": \"\",\n",
    "            \"time\": \"\"\n",
    "        },\n",
    "    },\n",
    "    \"musicX\":{\n",
    "        \"播放歌曲\": {\n",
    "            \"operate\": \"播放\",\n",
    "            \"song\": \"\",\n",
    "            \"author\": \"\",\n",
    "            \"source\": \"\",\n",
    "            \"tag\": \"\",\n",
    "            \"album\": \"\"\n",
    "        },\n",
    "    },\n",
    "    \"video\":{\n",
    "        \"播放视频\": {\n",
    "            \"operate\": [\"查询\", \"播放\"],\n",
    "            \"author\": \"\",\n",
    "            \"title\": \"\",\n",
    "            \"tag\": \"\",\n",
    "            \"source\": \"\"\n",
    "        },\n",
    "    },\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4be5f529",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'object': ['空调', '出风口'], 'operate': ['打开', '关闭', '锁定', '解锁'], 'position': ''}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "semantic_dict['airControl']['空调开关']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c295d43",
   "metadata": {},
   "outputs": [],
   "source": [
    "semantic_dict = {\n",
    "    \"airControl\": {\n",
    "        \"空调开关\": {\"object\": [\"空调\", \"出风口\"], \"operate\": [\"打开\", \"关闭\", \"锁定\", \"解锁\"], \"position\": \"\"}, \n",
    "        \"制冷制热\": {\"object\": \"空调\", \"mode\": [\"制冷\", \"制热\"], \"degree\": [\"最高\", \"中等\", \"最低\", \"极速\", \"自动\"], \"operate\": [\"打开\", \"关闭\"], \"position\": \"\"}, \n",
    "        \"其他模式\": {\"object\": \"空调\", \"mode\": [\"同步\", \"除雾\", \"除霜\", \"除湿\", \"循环\", \"节能\", \"舒适\", \"强劲\", \"空气净化\", \"负离子\", \"空气监测\"], \"operate\": [\"打开\", \"关闭\"], \"position\": \"\"}, \n",
    "        \"风速调节\": {\"object\": \"空调\", \"mode\": \"风速\", \"degree\": [\"最高\", \"中等\", \"最低\", \"高\", \"低\"], \"operate\": [\"调成\", \"调低\", \"调高\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"温度调节\": {\"object\": \"空调\", \"mode\": \"温度\", \"degree\": [\"最高\", \"中等\", \"最低\", \"高\", \"低\"], \"operate\": [\"调成\", \"调高\", \"调低\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"吹风模式\": {\"object\": \"空调\", \"mode\": \"吹风\", \"operate\": [\"打开\", \"关闭\", \"调成\"], \"position\": \"\"}\n",
    "    },\n",
    "    \"cmd\": {\n",
    "        \"打开和关闭页面\": {\"object\": \"\", \"mode\": \"页面\", \"operate\": [\"打开\", \"关闭\"]}, \n",
    "        \"蓝牙和网络\": {\"object\": [\"蓝牙\", \"wifi\", \"蜂窝移动数据\", \"热点\"], \"operate\": [\"打开\", \"关闭\", \"连接\", \"断连\"]}, \n",
    "        \"声音\": {\"object\": \"\", \"operate\": [\"调高\", \"调低\", \"静音\", \"查询\", \"打开\", \"关闭\"], \"value\": \"\", \"position\": \"\"}, \n",
    "        \"屏幕\": {\"object\": [\"屏幕\", \"仪表\"], \"mode\": \"亮度\", \"degree\": [\"最高\", \"最低\", \"中等\"], \"operate\": [\"调高\", \"调低\", \"调成\"], \"value\": \"\", \"position\": \"\"}, \n",
    "        \"主题壁纸\": {\"mode\": [\"主题\", \"壁纸\"], \"tag\": \"\"}\n",
    "    },\n",
    "    \"carControl\": {\n",
    "        \"车窗\": {\"object\": [\"车窗\", \"车窗锁\"], \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"天窗\": {\"object\": \"天窗\", \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"遮阳帘\": {\"object\": \"遮阳帘\", \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"座椅加热\": {\"object\": [\"座椅\", \"座椅靠背\", \"坐垫\"], \"mode\": \"加热\", \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\", \"调成\"], \"degree\": [\"最高\", \"最低\", \"高\", \"中\", \"低\", \"自动\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"座椅通风\": {\"object\": [\"座椅\", \"靠背\", \"坐垫\"], \"mode\": \"通风\", \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\"], \"degree\": [\"最大\", \"最小\", \"高\", \"中\", \"低\", \"自动\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"座椅按摩\": {\"object\": [\"座椅\", \"靠背\", \"坐垫\"], \"mode\": \"按摩\", \"modeValue\": \"\", \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\"], \"degree\": [\"最高\", \"最低\", \"高\", \"中\", \"低\", \"自动\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"座椅调节\": {\"object\": [\"座椅\", \"座椅后背\", \"座椅靠背\"], \"mode\": [\"座椅调节\"], \"operate\": [\"前进\", \"后退\", \"向上\", \"向下\", \"向左\", \"向右\", \"调成\"], \"degree\": [\"最前\", \"最后\"], \"position\": \"\", \"value\": \"\"}, \n",
    "        \"车门控制\": {\"object\": \"车门\", \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调大\", \"调小\"], \"position\": \"\"}, \n",
    "        \"其他控制\": {\"object\": \"\", \"mode\": \"\", \"operate\": [\"打开\", \"关闭\", \"暂停\", \"调高\", \"调低\", \"调成\", \"向左\", \"向右\"], \"degree\": [\"最高\", \"最低\", \"手动\"], \"value\": \"\", \"position\": \"\"}\n",
    "    },\n",
    "    \"vehicleInfo\": {\n",
    "        \"车辆信息查询\": {\"object\": \"\", \"operate\": \"查询\"}\n",
    "    },\n",
    "    \"telephone\": {\n",
    "        \"电话-呼叫\": {\"name\": \"\", \"number\": \"\"}, \n",
    "        \"电话-指令\": {\"operate\": \"\"}\n",
    "    },\n",
    "    \"app\": {\n",
    "        \"app\": {\"object\": \"\", \"operate\": [\"打开\", \"关闭\"]}\n",
    "    },\n",
    "    \"mapU\": {\n",
    "        \"导航\": {\"origin\": \"\", \"destination\": \"\", \"strategy\": [\"默认\", \"速度优先\", \"费用优先\", \"躲避拥堵\", \"高速优先\", \"不走高速\", \"大路优先\"], \"waypoints\": \"\"}, \n",
    "        \"搜索\": {\"keywords\": \"\", \"region\": \"\"}\n",
    "    },\n",
    "    \"weather\": {\n",
    "        \"查询\": {\"object\": [\"天气\", \"晴\", \"多云\", \"阴\", \"雨\", \"雾霾\", \"雪\", \"气温\"], \"operate\": \"查询\", \"city\": \"\", \"time\": \"\"}\n",
    "    },\n",
    "    \"musicX\": {\n",
    "        \"播放歌曲\": {\"operate\": \"播放\", \"song\": \"\", \"author\": \"\", \"source\": \"\", \"tag\": \"\", \"album\": \"\"}\n",
    "    },\n",
    "    \"video\": {\n",
    "        \"播放视频\": {\"operate\": [\"查询\", \"播放\"], \"author\": \"\", \"title\": \"\", \"tag\": \"\", \"source\": \"\"}\n",
    "    }\n",
    "}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
